<?php /* Smarty version Smarty-3.1.18, created on 2017-09-05 16:29:36
         compiled from "/Applications/MAMP/htdocs/PHP/jifenshop/protected/template/wap/cart.jiesuan.html" */ ?>
<?php /*%%SmartyHeaderCode:88305991559735109a39ba5-34902026%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
  'file_dependency' => 
  array (
    'f8fd1798011fe69a977c9bad9e3bff80911e6d54' => 
    array (
      0 => '/Applications/MAMP/htdocs/PHP/jifenshop/protected/template/wap/cart.jiesuan.html',
      1 => 1504600173,
      2 => 'file',
    ),
  ),
  'nocache_hash' => '88305991559735109a39ba5-34902026',
  'function' => 
  array (
  ),
  'version' => 'Smarty-3.1.18',
  'unifunc' => 'content_59735109cac091_49876834',
  'variables' => 
  array (
    'data' => 0,
    's' => 0,
    'integral_order' => 0,
    'g' => 0,
    'goods' => 0,
  ),
  'has_nocache_code' => false,
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_59735109cac091_49876834')) {function content_59735109cac091_49876834($_smarty_tpl) {?><?php echo $_smarty_tpl->getSubTemplate ("header.html", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array(), 0);?>

<body class="gr">

<div class="navBar">
	<a class="left" href="javascript:history.back()"><i class="return"></i></a>
	<div class="titleView">确认订单</div>
</div>

<div class="cart-jiesuan main-top">
	<div class="addressView">
		<?php if ($_smarty_tpl->tpl_vars['data']->value['address']->member_id==0) {?>
		<a href="javascript:void(0)" class="addressNo">+ 请选择收货地址</a>
		<?php } else { ?>
		<a href="javascript:void(0)" class="address push-ico">
			<div>
				<span>收货人：<?php echo $_smarty_tpl->tpl_vars['data']->value['address']->contactman;?>
　<?php echo $_smarty_tpl->tpl_vars['data']->value['address']->mobile;?>
</span>
				<span><?php echo $_smarty_tpl->tpl_vars['data']->value['address']->province;?>
<?php if ($_smarty_tpl->tpl_vars['data']->value['address']->province!=$_smarty_tpl->tpl_vars['data']->value['address']->city) {?> <?php echo $_smarty_tpl->tpl_vars['data']->value['address']->city;?>
<?php }?> <?php echo $_smarty_tpl->tpl_vars['data']->value['address']->district;?>
 <?php echo $_smarty_tpl->tpl_vars['data']->value['address']->address;?>
</span>
			</div>
		</a>
		<?php }?>
	</div>
	
	<section>
		<ul class="tableView tableView-light goods">
			<?php  $_smarty_tpl->tpl_vars['s'] = new Smarty_Variable; $_smarty_tpl->tpl_vars['s']->_loop = false;
 $_from = $_smarty_tpl->tpl_vars['data']->value['shops']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array');}
foreach ($_from as $_smarty_tpl->tpl_vars['s']->key => $_smarty_tpl->tpl_vars['s']->value) {
$_smarty_tpl->tpl_vars['s']->_loop = true;
?>
			<?php  $_smarty_tpl->tpl_vars['g'] = new Smarty_Variable; $_smarty_tpl->tpl_vars['g']->_loop = false;
 $_from = $_smarty_tpl->tpl_vars['s']->value->goods; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array');}
foreach ($_from as $_smarty_tpl->tpl_vars['g']->key => $_smarty_tpl->tpl_vars['g']->value) {
$_smarty_tpl->tpl_vars['g']->_loop = true;
?>
			<li>
				<h1>
					<li>
						<div class="right" price="<?php if (isset($_smarty_tpl->tpl_vars['integral_order']->value)) {?><?php echo $_smarty_tpl->tpl_vars['g']->value->integral;?>
<?php } else { ?><?php echo $_smarty_tpl->tpl_vars['g']->value->price;?>
<?php }?>" quantity="<?php echo $_smarty_tpl->tpl_vars['g']->value->quantity;?>
">
							<?php if (isset($_smarty_tpl->tpl_vars['integral_order']->value)) {?>
							<div class="price"><?php echo $_smarty_tpl->tpl_vars['g']->value->integral;?>
积分</div>
							<?php } else { ?>
							<div class="price">￥<?php echo number_format($_smarty_tpl->tpl_vars['g']->value->price,2);?>
</div>
							<div>× <?php echo $_smarty_tpl->tpl_vars['g']->value->quantity;?>
</div>
							<?php }?>
						</div>
						<a class="pic" href="wap.php?app=goods&act=detail&goods_id=<?php echo $_smarty_tpl->tpl_vars['g']->value->id;?>
" style="background-image:url(<?php echo $_smarty_tpl->tpl_vars['g']->value->default_pic;?>
);"></a>
						<a class="name" href="wap.php?app=goods&act=detail&goods_id=<?php echo $_smarty_tpl->tpl_vars['g']->value->id;?>
"><?php echo $_smarty_tpl->tpl_vars['g']->value->name;?>
</a>
						<div class="spec">规格：<?php echo $_smarty_tpl->tpl_vars['g']->value->spec;?>
</div>
					</li>
				</h1>
			</li>
			<?php } ?>
			<?php } ?>
		</ul>
		
		<?php if (is_array($_smarty_tpl->tpl_vars['data']->value['coupons'])&&count($_smarty_tpl->tpl_vars['data']->value['coupons'])>0) {?>
		<ul class="tableView tableView-noMargin tableView-light">
			<li class="coupon">
				<a href="javascript:void(0)">
					<h1><big></big>优惠券</h1>
				</a>
			</li>
		</ul>
		<textarea class="coupons" style="display:none;"><?php echo json_encode($_smarty_tpl->tpl_vars['data']->value['coupons']);?>
</textarea>
		<?php }?>
		
		<?php if (!isset($_smarty_tpl->tpl_vars['integral_order']->value)) {?>
		<ul class="tableView tableView-noMargin tableView-light payMethod">
			<li><h1>支付方式</h1></li>
			<li class="yue">
				<h1>
					<input type="radio" name="pay" id="yue" value="yue" method_name="余额支付" />
					<label for="yue"><em></em>余额支付</label>
				</h1>
			</li>
			<li class="wxpay">
				<h1>
					<input type="radio" name="pay" id="wxpay" value="wxpay_h5" method_name="微信支付" />
					<label for="wxpay"><em></em>微信支付</label>
				</h1>
			</li>
			<!--
			<li class="alipay">
				<h1>
					<input type="radio" name="pay" id="alipay" value="alipay" method_name="支付宝支付" />
					<label for="alipay"><em></em>支付宝支付</label>
				</h1>
			</li>
			-->
		</ul>
		<?php }?>
		
		<ul class="tableView tableView-noMargin tableView-light">
			<li><h1><big class="price">0.00</big><?php if (isset($_smarty_tpl->tpl_vars['integral_order']->value)) {?>商品积分<?php } else { ?>商品金额<?php }?></h1></li>
			<li><h1><big><?php if ($_smarty_tpl->tpl_vars['data']->value['shops'][0]->shipping_fee<=0) {?><span>包邮</span><?php } else { ?>￥<?php echo number_format($_smarty_tpl->tpl_vars['data']->value['shops'][0]->shipping_fee,2);?>
<?php }?></big>运费</h1></li>
		</ul>
	</section>
	
	<div class="bottomView toolBar ge-top">
		<a href="javascript:void(0)" class="btn">提交订单</a>
		<?php if (isset($_smarty_tpl->tpl_vars['integral_order']->value)) {?>
		<div>总积分: <span><?php echo $_smarty_tpl->tpl_vars['data']->value['total_price'];?>
</span></div>
		<?php } else { ?>
		<div>实付款: <span>￥<?php echo number_format($_smarty_tpl->tpl_vars['data']->value['total_price'],2);?>
</span></div>
		<?php }?>
	</div>
</div>

<form action="wap.php?app=cart&act=order_pay" method="post">
<input type="hidden" name="contactman" id="contactman" value="<?php echo $_smarty_tpl->tpl_vars['data']->value['address']->contactman;?>
" />
<input type="hidden" name="mobile" id="mobile" value="<?php echo $_smarty_tpl->tpl_vars['data']->value['address']->mobile;?>
" />
<input type="hidden" name="province" id="province" value="<?php echo $_smarty_tpl->tpl_vars['data']->value['address']->province;?>
" />
<input type="hidden" name="city" id="city" value="<?php echo $_smarty_tpl->tpl_vars['data']->value['address']->city;?>
" />
<input type="hidden" name="district" id="district" value="<?php echo $_smarty_tpl->tpl_vars['data']->value['address']->district;?>
" />
<input type="hidden" name="address" id="address" value="<?php echo $_smarty_tpl->tpl_vars['data']->value['address']->address;?>
" />
<input type="hidden" name="coupon_sn" id="coupon_sn" value="" />
<input type="hidden" name="total_price" value="<?php echo $_smarty_tpl->tpl_vars['data']->value['total_price'];?>
" />
<input type="hidden" name="pay_method" id="pay_method" value="<?php if (isset($_smarty_tpl->tpl_vars['integral_order']->value)) {?>integral<?php }?>" />
<input type="hidden" name="pay_method_name" id="pay_method_name" value="<?php if (isset($_smarty_tpl->tpl_vars['integral_order']->value)) {?>积分兑换<?php }?>" />
<textarea name="goods" style="display:none;"><?php echo stripslashes($_smarty_tpl->tpl_vars['goods']->value);?>
</textarea>
<?php if (isset($_smarty_tpl->tpl_vars['integral_order']->value)) {?><input type="hidden" name="integral_order" value="1" /><?php }?>
</form>
<input type="hidden" id="money" value="<?php echo $_smarty_tpl->tpl_vars['data']->value['money'];?>
" />
<input type="hidden" id="totalprice" value="<?php echo $_smarty_tpl->tpl_vars['data']->value['total_price'];?>
" />

<?php echo $_smarty_tpl->getSubTemplate ("footer.html", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array(), 0);?>

<script type="text/javascript" src="js/city.js"></script>
<script>
var origin_price = Number('<?php echo $_smarty_tpl->tpl_vars['data']->value['total_price'];?>
');
$(function(){
	$('.addressView a').click(getAddress);
	$('.coupon a').click(function(){
		var coupons = $('.coupons').val().formatJSON(), btns = [{
			text : '不使用优惠券',
			click : function(){
				$('.coupon big').html('');
				$('.bottomView span').html('￥'+origin_price.numberFormat(2)).priceFont('bigPrice');
				$('#coupon_sn').val('');
			}
		}];
		if($.isArray(coupons))for(var i=0; i<coupons.length; i++)btns.push({
			text : coupons[i].name+' -￥'+coupons[i].coupon_money.numberFormat(2),
			click : function(index){
				var i = index - 1;
				$('.coupon big').html(coupons[i].name+' -￥'+coupons[i].coupon_money.numberFormat(2));
				$('.bottomView span').html('￥'+(origin_price-coupons[i].coupon_money).numberFormat(2)).priceFont('bigPrice');
				$('#coupon_sn').val(coupons[i].sn);
			}
		});
		$.actionView('选择优惠券', btns);
	});
	$('.payMethod li').click(function(){
		var input = $(this).find('input');
		$('#pay_method').val(input.val());
		$('#pay_method_name').val(input.attr('method_name'));
	});
	if($('#money').val()*1<$('#totalprice').val()*1)$('.yue').hide();
	var totalPrice = 0;
	$('.goods .right').each(function(){
		totalPrice += $(this).attr('price')*1 * $(this).attr('quantity')*1;
	});
	$('big.price').html(<?php if (isset($_smarty_tpl->tpl_vars['integral_order']->value)) {?>totalPrice<?php } else { ?>'￥'+totalPrice.numberFormat(2)<?php }?>);
	<?php if (!isset($_smarty_tpl->tpl_vars['integral_order']->value)) {?>$('big, .goods .right .price, .bottomView span').priceFont('bigPrice');<?php }?>
	$('.bottomView .btn').click(function(){
		if(!$('#contactman').val().length || !$('#mobile').val().length || !$('#province').val().length || !$('#city').val().length || !$('#district').val().length || !$('#address').val().length){
			$.overloadError('请选择收货地址');
			return;
		}
		// 再次确认
		alertUI({
			cls : 'ios7-alert',
			html : '<p>确认兑换该商品吗？</p>',
			btns : [{
				text : ' 确定 ',
				click : function(){ 
					<?php if (!isset($_smarty_tpl->tpl_vars['integral_order']->value)) {?>
					if(!$('#pay_method').val()){
						$.overloadError('请选择支付方式');
						return;
					}
					if($('#money').val()*1<=0 && $('#pay_method').val()=='yue'){
						$.overloadError('当前支付余额不足');
						return;
					}
					if($('#money').val()*1>0 && $('#pay_method').val()=='yue'){
						$('form').attr('action', 'api.php?app=cart&act=order').ajaxsubmit({
							dataType : 'json',
							success : function(json){
								if(json.error!=0){ $.overloadError(json.msg);return }
								location.href = 'wap.php?app=cart&act=order_complete&order_sn='+json.data.order_sn;
							}
						});
					}else{
						$('form').attr('action', 'wap.php?app=cart&act=order_pay').submit();
					}
					<?php } else { ?>
					$('form').attr('action', 'api.php?app=cart&act=order').ajaxsubmit({
						dataType : 'json',
						success : function(json){
							if(json.error!=0){ $.overloadError(json.msg);return }
							location.href = 'wap.php?app=cart&act=order_complete&integral_order=1&order_sn='+json.data.order_sn;
						}
					});
					<?php }?>
				}
			},{
				text : ' 取消 ',
				click : function(){
					alertUI();
				}
			}]
		});
		
	});
});

function getAddress(){
	var _this = $(this);
	if(_this.hasClass('addressNo')){
		addAddress();
	}else{
		$.getJSON('api.php?app=address&act=list_address', function(json){
			if(json.error!=0){ $.overloadError(json.msg);return }
			if(!$.isArray(json.data)){ $.overloadError('没有收货地址');return }
			var html = '<div class="faceView gr">\
							<div class="navBar">\
								<a class="left" href="javascript:history.back()"><i class="return"></i></a>\
								<div class="titleView">收货地址</div>\
								<a class="right" href="javascript:void(0)">添加</a>\
							</div>\
							<div class="address-list main-padding-top">\
								<section>';
									for(var i=0; i<json.data.length; i++){
									html += '<ul class="list tableView tableView-noLine">\
										<li>\
											<h1>\
												<div class="name">'+json.data[i].contactman+'　'+json.data[i].mobile+'</div>\
												<div class="address">'+json.data[i].province+(json.data[i].province!=json.data[i].city?' '+json.data[i].city:'')+' '+json.data[i].district+' '+json.data[i].address+'</div>\
											</h1>\
										</li>\
									</ul>';
									}
								html += '</section>\
							</div>\
						</div>';
			$('body').append(html);
			var faceView = bindFaceView(null, '.address-list');
			//scrollFaceView('.address-list');
			faceView.find('.tableView li').each(function(i){
				$(this).data('data', json.data[i]);
			}).click(function(){
				setAddress($(this));
			});
			faceView.find('.navBar .right').click(function(){
				addAddress();
			});
		});
	}
}
function setAddress(_this){
	var data = _this.data('data');
	$('.addressView a').replaceWith('<a href="javascript:void(0)" class="address push-ico">\
										<div>\
											<span>'+data.contactman+'　'+data.mobile+'</span>\
											<span>'+data.province+((data.province!=data.city)?' '+data.city:'')+' '+data.district+' '+data.address+'</span>\
										</div>\
									</a>');
	$('#contactman').val(data.contactman);
	$('#mobile').val(data.mobile);
	$('#province').val(data.province);
	$('#city').val(data.city);
	$('#district').val(data.district);
	$('#address').val(data.address);
	$('.addressView a').click(getAddress);
	removeFaceView();
}

function addAddress(){
	showAddAddress(function(){
		bindFaceView(null, '.address-info');
		$('.address-info #contactman').placeholder('请输入收货人姓名');
		$('.address-info #mobile').placeholder('请输入手机号码');
		$('.address-info #address').placeholder('请输入地址');
		firstValue = false;
		tipShow = false;
		showCity({ province:'#provinces', city:'#citys', district:'#districts', applyName:true, getLocation:true });
		$('.address-info .selects').onclick(function(){
			$.actionpicker({
				title : '请选择地区',
				rightBtn : {
					text : '确定',
					click : function(){
						$('.selects').append(this.find('select'));
						$.actionpicker();
					}
				},
				before : function(){
					this.append($('.selects').find('select'));
					this.selectpicker({
						cls : 'areapicker',
						autoWidth : false,
						select : function(component, row){
							var html = comboCity($('#provinces').selected().val(), $('#citys').selected().val(), $('#districts').selected().val());
							$('.address-info .selects').addClass('selects-x');
							$('.address-info .selects div').html(html);
						},
						complete : function(){
							var html = comboCity($('#provinces').selected().val(), $('#citys').selected().val(), $('#districts').selected().val());
							$('.address-info .selects').addClass('selects-x');
							$('.address-info .selects div').html(html);
						}
					}, $('#provinces'), $('#citys'), $('#districts'));
				},
				close : function(){
					$('.selects').append(this.find('select'));
				}
			});
		});
		$('.address-info .buttonView .btn').click(function(){
			var contactman = $('.address-info #contactman').val(), mobile = $('.address-info #mobile').val(),
				province = $('.address-info #provinces').val(), city = $('.address-info #citys').val(), district = $('.address-info #districts').val(), address = $('.address-info #address').val();
			if(!contactman.length || !mobile.length || !address.length ){
				$.overloadError('请填写完整');
				return;
			}
			$.postJSON('api.php?app=address&act=add_address', { contactman:contactman, mobile:mobile, province:province, city:city, district:district, address:address }, function(json){
				$('.addressView a').replaceWith('<a href="javascript:void(0)" class="address push-ico">\
													<div>\
														<span>'+contactman+'　'+mobile+'</span>\
														<span>'+province+(province!=city?' '+city:'')+' '+district+' '+address+'</span>\
													</div>\
												</a>');
				$('#contactman').val(contactman);
				$('#mobile').val(mobile);
				$('#province').val(province);
				$('#city').val(city);
				$('#district').val(district);
				$('#address').val(address);
				$('.addressView a').click(getAddress);
				if($('.address-list').length){
					var ul = $('<ul class="list tableView tableView-noLine">\
									<li>\
										<h1>\
											<div class="name">'+contactman+'　'+mobile+'</div>\
											<div class="address">'+province+(province!=city?' '+city:'')+' '+district+' '+address+'</div>\
										</h1>\
									</li>\
								</ul>');
					$('.address-list section').append(ul);
					ul.find('li').data('data', {
						contactman:contactman, mobile:mobile, province:province, city:city, district:district, address:address
					}).click(function(){
						setAddress($(this));
					});
				}
				removeFaceView();
			});
		});
	});
}
function showAddAddress(fn){
	var html = '<div class="faceView gr">\
					<div class="navBar">\
						<a class="left" href="javascript:history.back()"><i class="return"></i></a>\
						<div class="titleView">添加收货地址</div>\
					</div>\
					<div class="address-info main-top">\
						<ul class="tableView tableView-noMargin tableView-light">\
							<li>\
								<h1>\
									<div class="row">\
										<span>收货人姓名</span>\
										<input type="text" name="contactman" id="contactman" />\
									</div>\
								</h1>\
							</li>\
							<li>\
								<h1>\
									<div class="row">\
										<span>手机号码</span>\
										<input type="tel" name="mobile" id="mobile" />\
									</div>\
								</h1>\
							</li>\
							<li>\
								<h1 class="push-ico">\
									<div class="row">\
										<span>所在地区</span>\
										<div class="selects">\
											<div>请选择地区</div>\
											<select name="province" id="provinces" onchange="changeProvince({ province:\'#provinces\',city:\'#citys\',district:\'#districts\',applyName:true })"></select>\
											<select name="city" id="citys" onchange="changeCity({ city:\'#citys\',district:\'#districts\',applyName:true })"></select>\
											<select name="district" id="districts"></select>\
										</div>\
									</div>\
								</h1>\
							</li>\
							<li>\
								<h1>\
									<div class="row">\
										<span>地址</span>\
										<input type="text" name="address" id="address" />\
									</div>\
								</h1>\
							</li>\
						</ul>\
						<div class="buttonView">\
							<a class="btn" href="javascript:void(0)">确定</a>\
						</div>\
					</div>\
				</div>';
	$('body').append(html);
	fn();
}
</script><?php }} ?>
